<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/include/common/formbackhead.jsp"%>
<%!
private class PageAction extends BaseAction{
	ResultSet rs = null;
	CrudDataEntity crud =  null;
	
	//准备action的环境变量 每次请次都会执行此方法 可在此方法中初如化一些变量
	protected void prepareActionEnv() throws Exception{
		
	}
	
	//加載頁面默認數據
	protected boolean onLoadDefault() throws Exception{
		if(!form.isNullOrEmpty("ctn004sn")){
			rs = utils.executeQuery("info","select * from cotton..ctn004 where sn = '"+form.gpsv("ctn004sn")+"'");
			if(rs.next()){
				form.FromResultSet(rs, false);
			}else{
				ret.setWarningInfo("此單已刪除,如需要請重新新增!");
				page.getToolbar().disableAllButtonExcept("newnext");
			}
		}
		return true ;
	}
	
	protected void EndProcess() throws Exception{
		if("0".equalsIgnoreCase(form.gpsv("enab"))){
			page.getToolbar().disableAllButtonExcept("newnext,save");
		}
	}
	
	//处理储存驗證
	protected void onSaveValidate() throws Exception{
		crud = form.getCrudDataEntity("info","cotton..ctn004","sn");
		crud.spsv("sn", form.gpsv("ctn004sn"));
		crud.setSpportSimple(true);
		crud.spsv("hrnum", form.gpsv("hrnum"));
		crud.spsv("chname", form.gpsv("chname"));
		crud.spsv("hr003name", form.gpsv("hr003name"));
		crud.spsv("groupname", form.gpsv("groupName"));
		crud.spsv("isleader", form.gpsv("isleader"));
		crud.spsv("enab", form.gpsv("enab","1"));
		
		if(crud.isExist("hrnum")){
			ret.setErrorInfo("工號重複!");
		}
	}
	
	//執行儲存
	protected void doSave() throws Exception{
		//1.儲存
		if(crud.isInsert()){
			crud.setGetLastKey(true);
			crud.appendCols("prgName,crtDay,crtName,crtIp,updDay,updName,updIp");
		}else{
			crud.appendCols("prgName,updDay,updName,updIp");
		}
		crud.save();
		
		ret.setOkInfo("儲存成功!");
		if(form.isNullOrEmpty("ctn004sn")){
			form.spsv("ctn004sn", crud.gpsv("sn"));
		}
	}
	
	//取消驗證
	protected void onCancelValidate() throws Exception{
		if(form.isNullOrEmpty("ctn004sn")){
			ret.setErrorInfo("沒有主鍵值,不能取消!");
		}
	}
	
		//執行取消
	protected void doCancel() throws Exception{
		CrudDataEntity crud = form.getCrudDataEntity("info","cotton..ctn004","sn");
		crud.spsv("sn", form.gpsv("ctn004sn"));
		crud.cancel();
		ret.setOkInfo("取消成功!");
	}


}
%>
<%@include file="/include/common/formbackend.jsp"%>